﻿/*
*
*  Author:随波逐流
*  Date:2013/8/24
*  HomePage:http://www.yaoboweb.com
*
*/
;
jQuery &&
function(a) {
    function b(c) {
        function g(c, d, f) {
            function G(a) {
                M(a.clientX - B)
            }
            function H() {
                e.unbind("mousemove", G).unbind("mouseup", H)
            }
            function I(a, b, c) {
                return a *= y,
                C = a,
                c ? (o.animate({
                    left: a + "px"
                }), m.animate({
                    width: a + v + "px"
                },
                function() {
                    b && b()
                }), void 0) : (o.css("left", a + "px"), m.css("width", a + v + "px"), b && b(), void 0)
            }
            function J(a, b) {
                var c;
                a = g.valueLeft < g.valueRight ? a: 1 - a,
                c = a,
                a = a * (A - z) + z,
                a = g.valueFloat ? a.toFixed(g.valueFloat || 0) : Math.round(a),
                D = a,
                j.val(a),
                k && k.html((g.editValue ? "": a) + g.valueSuf),
                o.attr("title", a),
                g.valueChange && g.valueChange(D, c, f),
                g.percent = c,
                b && b()
            }
            function K(a, b) {
                return b <= a[0] ? a[0] : b >= a[1] ? a[1] : b
            }
            function L(a, b, c) {
                a = K([z, A], a),
                g.valueLeft > g.valueRight && (a = A + z - a),
                a = (a - z) / (A - z),
                J(a,
                function() {
                    I(a || 0, b, c)
                })
            }
            function M(a, b) {
                a = K([0, y], Math.floor(a)) / y,
                I(a,
                function() {
                    J(a || 0, b)
                })
            }
            var i, j, k, l, m, n, o, p, q, r, g = a.extend({},
            b.config, c),
            h = d;
            i = a(h),
            r = a(g.slidValueShowBox),
            j = a("input[setValue]", h),
            0 === j.length ? j = a("<input class='slider-inp' type='hidden' />") : j.attr("type", "hidden"),
            k = a(g.slidValueSuf),
            l = a(g.slidMain),
            oMainIn = a(g.slidMainIn),
            m = a(g.slidBar),
            n = a(g.slidBarBg),
            o = a(g.slidBlock);
            var s;
            s = 1 === j.length && /\,/.test(s = j.attr("setValue")) ? s.split(",") : [],
            g.valueSuf = j.attr("setValueSuf") || g.valueSuf,
            g.valueFloat = j.attr("setValueFloat") || g.valueFloat,
            s.length >= 2 && (g.setValue = s),
            g.valueLeft = parseFloat(g.setValue[0]) || 0,
            g.valueRight = parseFloat(g.setValue[1]) || 0,
            g.valueInit = parseFloat(g.setValue[2]) || 0,
            l.append(oMainIn.append(n, m, o)),
            g.showRange && (p = a(g.slidLeft), q = a(g.slidRight), l.prepend(p.html(g.valueLeft)), l.append(q.html(g.valueRight)));
            var t, u, v, w, y, z, A, B = 0,
            C = 0,
            D = 0,
            E = 1;
            g.valueLeft > g.valueRight ? (z = g.valueRight, A = g.valueLeft) : (z = g.valueLeft, A = g.valueRight),
            r.append(j),
            g.showValue && (r.append(k), g.editValue && j.attr("type", "text")),
            oMainIn.width(g.slidWidth),
            i.append(r),
            i.prepend(l),
            l.show(),
            u = o.width(),
            v = Math.floor(u / 2),
            w = Math.floor(o.height() / 2),
            o.css("marginTop", -w),
            y = g.slidWidth - u,
            L(g.valueInit, null, 1),
            g.showValue && g.editValue && j.change(function() {
                document.title += 1,
                t && clearTimeout(t),
                t = setTimeout(function() {
                    var a = j.val();
                    /^[\-\+]?\d+(\.\d+)?$/.test(a) && (a = Math.floor(parseFloat(a)), L(a, null, 1))
                },
                30)
            }),
            o.mousedown(function(a) {
                return B = a.clientX - C,
                e.bind("mousemove", G).bind("mouseup", H),
                !1
            }).click(function() {
                g.blockClick && g.blockClick()
            });
            var F = {};
            return F.keepMove = function(a) {
                a = K([0, 1], a),
                J(a,
                function() {
                    o.stop(),
                    m.stop(),
                    I(a, 0, E),
                    E = 0
                })
            },
            F.valueChange = function(a) {
                g.valueChange = a
            },
            F.percent = function() {
                return g.percent
            },
            F
        }
        var f, d = {
            index: 0,
            YBslider: []
        },
        e = a(document);
        return f = a(c.slidBox),
        0 === f.length && (f = a(document.body)),
        a.each(f,
        function() {
            var a = g(c, this, d.index);
            d.YBslider[d.index] = {},
            d.YBslider[d.index].keepMove = a.keepMove,
            d.YBslider[d.index].valueChange = a.valueChange,
            d.YBslider[d.index].percent = a.percent,
            d.index = d.index + 1
        }),
        d
    }
    b.config = {
        slidMain: "<span class='slider-main' style='display:none' />",
        slidMainIn: "<span class='slider-main-in' />",
        slidBar: "<i class='slider-bar' />",
        slidBarBg: "<i class='slider-bar-bg' />",
        slidBlock: "<a class='slider-black' href='javascript:;' />",
        slidLeft: "<span class='slider-l-num' />",
        slidRight: "<span class='slider-r-num' />",
        slidValueShowBox: "<span class='slider-value-box' />",
        slidValueSuf: "<span class='slider-value-suf' />",
        slidWidth: 180,
        valueLeft: 0,
        valueRight: 0,
        valueInit: 0,
        valueFloat: 0,
        showValue: !1,
        valueSuf: "",
        editValue: !1,
        showRange: !1
    },
    a.extend({
        YBslider: b
    })
} (jQuery);